package com.mao.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mao.common.Result;
import com.mao.dto.OrdersDto;
import com.mao.entity.Orders;
import com.mao.service.OrdersService;
import com.sun.org.apache.xpath.internal.operations.Or;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
@RequestMapping("/order")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    /**
     * 用户下单
     * @param orders
     * @return
     */
    @PostMapping("/submit")
    public Result<String> submit(@RequestBody Orders orders){
        ordersService.submit(orders);
        return Result.success("下单成功");
    }

    /**
     * 用户展示订单
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/userPage")
    public Result<Page> user_Orders(int page,int pageSize){
        Page<OrdersDto> ordersDtoPage = ordersService.userToOrders(page, pageSize);
        return Result.success(ordersDtoPage);
    }


    /**
     * 分页查询订单
     * @param page
     * @param pageSize
     * @param number
     * @param beginTime
     * @param endTime
     * @return
     */
    @GetMapping("/page")
    public Result<Page> page(int page,int pageSize, Long number, String beginTime, String endTime){
        Page<Orders> ordersPage = ordersService.page(page, pageSize, number, beginTime, endTime);
        return Result.success(ordersPage);
    }


    /**
     * 修改订单
     * @param orders
     * @return
     */
    @PutMapping
    public Result<String> Modify_order(@RequestBody Orders orders){
        ordersService.Modify_the_order(orders);
        return Result.success("成功修改订单");
    }

    /**
     * 再次进行下单
     * @param orders
     * @return
     */
    @PostMapping("/again")
    public Result<String> add_one(@RequestBody Orders orders){
        ordersService.add_one_order(orders);
        return Result.success("成功再来一单");
    }


}
